﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Com.OpenCode.Framework.DevForm
{
    public partial class OpenCodeForm : XtraForm
    {
        public OpenCodeForm()
        {
            InitializeComponent();
        }

        private bool _Loaded;

        protected override void OnLoad(EventArgs e)
        {
            if (!_Loaded)
            {
                try
                {
                    OpenCodeSplashScreenManager.Show();
                    base.OnLoad(e);
                    OnStartLoad();
                    _Loaded = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    OpenCodeSplashScreenManager.Close();
                }
            }
        }

        protected virtual void OnStartLoad()
        {
            StartPosition = FormStartPosition.CenterParent;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            Owner = MainForm.Instance;
        }

        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            int WM_KEYDOWN = 256;
            int WM_SYSKEYDOWN = 260;
            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
            {
                switch (keyData)
                {
                    case Keys.Escape:
                        this.Close();
                        break;
                }
            }
            return false;
        }

    }
}